package KharkovITCourses.proc.loop.selection_sort_optimized;

/**
 * Created with IntelliJ IDEA.
 * User: ZefiR
 * Date: 18.01.13
 * Time: 23:13
 * To change this template use File | Settings | File Templates.
 */
public class SelectionSort
{
    public static void sort(int[] arr) {
        for (int barrier = 0; barrier < arr.length - 1; barrier++) {
            int min = arr[barrier];
            int minIndex = barrier;
            for (int index = barrier + 1; index < arr.length; index++) {
                if (min > arr[index]) {
                    min = arr[index];
                    minIndex = index;
                }
            }
            if (minIndex != barrier) {
                arr[minIndex] = arr[barrier];
                arr[barrier] = min;
            }
        }
    }
}
